using System;
using System.ComponentModel;
using System.Transactions;

using SIS.ENT;
using SIS.DAL;

namespace SIS.BLL
{

    /// <summary>
    /// The DepartmentTableManager class is responsible for managing BO.DepartmentTable objects in the system.
    /// </summary>
    [DataObjectAttribute()]
    public class DepartmentTableManager
    {

        #region "Public Methods"

        /// <summary>
        /// Gets a list with all DepartmentTable objects in the database.
        /// </summary>
        /// <returns>A list with all DepartmentTable from the database when the database contains any, or null otherwise.</returns>
        [DataObjectMethod(DataObjectMethodType.Select, true)]
        public static DepartmentTableList GetList(int SchoolKey, int LocationKey)
        {
            return DepartmentTableDB.GetList(SchoolKey, LocationKey);
        }

        /// <summary>
        /// Gets a single DepartmentTable from the database without its data.
        /// </summary>
        /// <param name="schoolKey">The SchoolKey of the DepartmentTable in the database.</param>
        /// <returns>A DepartmentTable object when the SchoolKey exists in the database, or <see langword="null"/> otherwise.</returns>
        [DataObjectMethod(DataObjectMethodType.Select, false)]
        public static DepartmentTable GetItem(int schoolKey, int LocationKey)
        {
            return GetItem(schoolKey, LocationKey, false);
        }

        /// <summary>
        /// Gets a single DepartmentTable from the database.
        /// </summary>
        /// <param name="schoolKey">The SchoolKey of the DepartmentTable in the database.</param>
        /// <param name="getDepartmentTableRecords">Determines whether to load all associated DepartmentTable records as well.</param>
        /// <returns>
        /// A DepartmentTable object when the SchoolKey exists in the database, or <see langword="null"/> otherwise.
        /// </returns>
        [DataObjectMethod(DataObjectMethodType.Select, false)]
        public static DepartmentTable GetItem(int schoolKey, int LocationKey, bool getDepartmentTableRecords)
        {
            DepartmentTable myDepartmentTable = DepartmentTableDB.GetItem(schoolKey, LocationKey);
            return myDepartmentTable;
        }

        /// <summary>
        /// Saves a DepartmentTable in the database.
        /// </summary>
        /// <param name="myDepartmentTable">The DepartmentTable instance to save.</param>
        /// <returns>The new SchoolKey if the DepartmentTable is new in the database or the existing SchoolKey when an item was updated.</returns>
        [DataObjectMethod(DataObjectMethodType.Update, true)]
        public static int Save(DepartmentTable myDepartmentTable)
        {
            using (TransactionScope myTransactionScope = new TransactionScope())
            {
                int departmentKey = DepartmentTableDB.Save(myDepartmentTable);

                //  Assign the DepartmentTable its new (or existing SchoolKey).
                myDepartmentTable.DepartmentKey = departmentKey;

                myTransactionScope.Complete();

                return departmentKey;
            }
        }

        /// <summary>
        /// Deletes a DepartmentTable from the database.
        /// </summary>
        /// <param name="myDepartmentTable">The DepartmentTable instance to delete.</param>
        /// <returns>Returns true when the object was deleted successfully, or false otherwise.</returns>
        //[DataObjectMethod(DataObjectMethodType.Delete, true)]
        //public static bool Delete(DepartmentTable myDepartmentTable)
        //{
        //    return DepartmentTableDB.Delete(myDepartmentTable.SchoolKey);
        //}

        [DataObjectMethod(DataObjectMethodType.Delete, true)]
        public static bool Delete(Int32 DepartmentKey, Int32 SchoolKey)
        {
            return DepartmentTableDB.Delete(DepartmentKey, SchoolKey);
        }

        #endregion

    }

}
